home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Files / XTND 1.3.6 / Application Examples / PascalSource / THINK ƒ / XTNDInterface.p < prev    next >
Encoding:
Text File  |  1992-02-06  |  10.7 KB  |  231 lines  |  [TEXT/PJMM]

  1. {**************************************************************}
  2. {*                                                                        *}
  3. {*    XTNDInterface.p                                                        *}
  4. {*                                                                        *}
  5. {*    Claris XTND Architecture application header file                                *}
  6. {*                                                                        *}
  7. {*    Copyright © 1989-91 Claris Corporation                                        *}
  8. {*    All Rights Reserved                                                        *}
  9. {*                                                                        *}
  10. {**************************************************************}
  11. UNIT XTNDInterface;
  12. INTERFACE
  13.     USES
  14.         types, osutils, files, folders, QuickDraw, Dialogs;
  15.     CONST
  16.     { Defines for XTND Version }
  17.  
  18.         xtndVersion = 2;
  19.  
  20.     { Defines for file types }
  21.         xtndTranslatorFileType = 'Fltr';
  22.  
  23.     { Defines for resource types }
  24.         translatorDescription = 'FTYP';
  25.         textImportType = 'FLTI';
  26.         textExportType = 'FLTE';
  27.         pictImportType = 'PFLT';
  28.  
  29.     { Flag values for translator characteristics which are set in TransDescribe and FTYP }
  30.         ftypIsSpecial = $0001;
  31.         ftypHasPreferences = $0002;    { Reserved for future use }
  32.         ftypNeedsResources = $0004;
  33.         ftypWritesResources = $0008;    { Reserved for future use }
  34.         ftypOnlyPreferences = $0010;    { Reserved for future use }
  35.         ftypIsLocalized = $0020;
  36.  
  37.     { Type of translators to be included in list }
  38.         allowTypeMask = $00FF;
  39.         allowText = $0001;
  40.         allowGraphics = $0002;    { Reserved for future use }
  41.         allowDataBase = $0004;    { Reserved for future use }
  42.         allowPict = $0008;
  43.         allowOtherTypes = $0080;    { Reserved for future use }
  44.         allowAllTypes = $00FF;
  45.  
  46.     { Use of translators to be included in list }
  47.         allowUseMask = $FF00;
  48.         allowImport = $0100;
  49.         allowExport = $0200;
  50.         allowOtherUses = $8000;    { Reserved for future use }
  51.         allowAllUses = $FF00;
  52.  
  53.     { Error codes which the XTND System can return }
  54.  
  55.         badXTNDVersionErr = -9991;
  56.         noTransMatchErr = -9999;
  57.  
  58.     { Error codes which a translator can return }
  59.  
  60.         badImportFileErr = 12;
  61.         translationCanceledErr = 32767;
  62.  
  63.     TYPE
  64. { ModalFilterProcPtr = ProcPtr;}
  65.         XTNDDlgHookProcPtr = ProcPtr; { XTNDDlgHook(item: INTEGER; theDialog: DialogPtr;}
  66. {                mySFParamPtr: Ptr; VAR changedFlag: Boolean; unusedParm: Longint); }
  67.         TransProcPtr = ProcPtr; { Translator(pb: ParamBlk); C;    (Note: this uses C calling conventions) }
  68.  
  69.     { The MatchInfo data stucture defines a single file type (and possibly creator type)}
  70.     {      that a translator can recognize.}
  71.         MatchInfo = RECORD
  72.                 docCreator: ResType;        { Document creator, eg 'MACA' - MacWrite }
  73.                 docType: ResType;        { Document type, eg 'WORD' - MacWrite    }
  74.                 exactMatch: BOOLEAN;        { If TRUE, Creator MUST match }
  75.                 creatorAndTypeMask: SignedByte;        { Flags telling which bytes of file & creator types matter }
  76.             END;
  77.  
  78.  
  79.     { The TransDescribe data stucture defines an import/export translator.  There is one }
  80.     { of these (corresponds to the 'FTYP' resource) for every import/export translator. }
  81.         TransDescrHandle = ^TransDescrPtr;
  82.         TransDescrPtr = ^TransDescribe;
  83.         TransDescribe = RECORD
  84.                 version: INTEGER;        { Version of this FTYP (currently 2) }
  85.                 translatorType: ResType;        { Type of translator (ie, 'PFLT' for pictures) }
  86.                 codeResID: INTEGER;        { Resource ID of translator code resource }
  87.                 FDIFResID: INTEGER;        { Resource ID of 'FDIF' (or -1 if none) }
  88.                 numVersBytes: INTEGER;        { Number of bytes for version check (zero if no check) }
  89.                 versBytesOffSet: LONGINT;        { Offset into file for version check }
  90.                 versBytes: PACKED ARRAY[0..15] OF SIgnedByte; { Byte values we are looking for (max 16) }
  91.                 appWDRefNum: INTEGER;        { vRefNum of the volume containing the application folder }
  92.                 unused1: INTEGER;        {  }
  93.                 pathLength: INTEGER;        { Number of times this file has been translated }
  94.                 flags: INTEGER;        { Flags for filter characteristics }
  95.                                             { bit 0 - set if this filter won't work with All Available }
  96.                                             { bit 1 - set if this filter has a preferences dialog }
  97.                                             { bit 2 - set if this filter must be able to read its resources }
  98.                                             { bit 3 - 4 reserved for future use - must be zero for this version }
  99.                                             { bit 5 - set if this filter is localized to a particular language }
  100.                                             { bit 6 - 14 reserved for future use - must be zero for this version }
  101.                                             { bit 15 - Used internally - must be zero for this version }
  102.                 transIndex: INTEGER;        { Internal XTND use only - Index of this translator in the list stored by the FINI }
  103.                 resRefNum: INTEGER;        { RefNum of resource fork of the translator file when open }
  104.                 directoryID: LONGINT;        { Directory ID of the folder containing the filter }
  105.                 vRefNum: INTEGER;        { Volume RefNum of volume which contains filter directory }
  106.                 fileName: Str31;            { Name of file if this is an external filter }
  107.                 numMatches: INTEGER;        { Number of Matches for this translator (0 means all files) }
  108.                 matches: ARRAY[0..9] OF MatchInfo; { An array of all file matches for this translator }
  109.                 name: Str31;            { Description of translator - appears in pop-up menus }
  110.             END;
  111.  
  112.     { The XTND file parameter block.        }
  113.         SFParamPtr = ^SFParamBlock;
  114.         SFParamBlock = RECORD
  115.     { The following fields must be the same in this structure and MatchTranslatorBlock }
  116.                 allowFlags: LongInt;                { --> Flags which indicate Translators to be used }
  117.                 numStandard: LongInt;                { --> How many "standard" file types }
  118.                 standard: TransDescrPtr;            { --> Native file format information }
  119.                 ioResult: OSErr;                    { <-- Errors reported through this variable }
  120.                 chosenTranslator: Integer;            { <-- chosen Translator number }
  121.                 theChosenTranslator: TransDescrPtr;    { <-- Points to the Chosen Translator }
  122.         { End of common fields }
  123.                 fileReply: ^SFReply;                { <-- File information is returned through this pointer }
  124.                 applicNativeType: ResType;            { --> Application native document file type, for use when library cannot be found }
  125.                 XTNDDlogHook: XTNDDlgHookProcPtr;    { --> Pointer to your SF dialog hook }
  126.                 currentMenuItem: INTEGER;                { <-- chosen menu item (GetFile) }
  127.                 currentSaveItem: INTEGER;                { <-- chosen menu item (PutFile) }
  128.                 where: Point;                { --> Top left corner of dialog, if zero, center on screen }
  129.                 prompt: StringPtr;            { --> Pascal string which is displayed on dialog }
  130.                 buttonTitle: StringPtr;            { --> Pascal string which replaces the "Open" or "Save" button }
  131.                 origName: StringPtr;            { --> Pascal string which is the original name in a PutFile }
  132.                 dialogID: INTEGER;                { --> Resource number of your dialog template }
  133.                 SFFilterProc: ModalFilterProcPtr;    { --> Pointer to your modal dialog filter proc }
  134.                 showAllFiles: BOOLEAN;                { --> TRUE if you want all files to be shown }
  135.                 useMyTransList: BOOLEAN;                { --> TRUE if you are using chosenTranslator and theChosenTranslator to input a list of translators to be used in creating the popup menu }
  136.                 myFileFilter: FileFilterProcPtr;    { --> Pointer to your SF Filter Proc }
  137.                 Unused: LONGINT;                { Reserved for future use, must be zero }
  138.             END;
  139.  
  140.     { This parameter block is used to find a translator to read a file.}
  141.     {    }
  142.         MatchTranslatorPtr = ^MatchTranslatorBlock;
  143.         MatchTranslatorBlock = RECORD
  144.         { The following fields must be the same in this structure and in XTNDParamBlock }
  145.                 allowFlags: LONGINT;        { --> Flags which indicate Translators to be used }
  146.                 numStandard: LONGINT;        { --> How many "standard" file types }
  147.                 standard: TransDescrPtr;    { --> Native file format information }
  148.                 ioResult: OSErr;            { <-- IO Result from XTND library }
  149.                 chosenTranslator: INTEGER;    { <-> On input, number of translators supplied in the_Chosen_Translator; on output, chosen Translator number }
  150.                 theChosenTranslator: TransDescrPtr;{ <-> On input, Pointer to list of translators to build popup menu from (UseMyTransList must be true if you supply this list); on output, pointer to the Chosen Translator }
  151.     { End of common fields }
  152.                 fileName: StringPtr;        { --> File name }
  153.                 vRefNum: INTEGER;            { --> Volume Reference Number of file }
  154.                 ioDirID: LongInt;            { --> Directory id of file }
  155.                 initFlag: Boolean;            { --> TRUE if the list of translators should be rebuilt }
  156.                 useTransList: Boolean;        { --> TRUE if you are using chosenTranslator and theChosenTranslator }
  157. {                                                   to input a list of translators }
  158.                 oneTrans: TransDescrPtr;    { --> If this is supplied, it will be tried instead of}
  159. {                                                  searching all available translators }
  160.                 unused: ARRAY[0..3] OF LONGINT;    { Reserved for future use, must be zero }
  161.             END;
  162.  
  163.         SelectParamPtr = ^SelectParamBlock;
  164.         SelectParamBlock = RECORD
  165.                 translatorVersion: INTEGER;        { To select by translator type }
  166.                 translatorType: ResType;        { and version }
  167.                 includeFlags: LONGINT;        { Include any of these translator types }
  168.                 excludeFlags: LONGINT;        { Exclude all of these translator types }
  169.                 includeTrans: INTEGER;        { Include translators with any of these flags set }
  170.                 excludeTrans: INTEGER;        { Excluded translator with any of these flags set }
  171.                 transName: StringPtr;    { Include only translators with this name }
  172.                 PBVersion: LONGINT;        { ••• MUST be ONE (1) for this version ••• }
  173.                 MenuSortFlag: Boolean;        { TRUE if you want the list sorted and duplicates removed as when the XTND System creates a menu in ClarisGetFile or ClarisPutFile for you }
  174.                 unused1: Boolean;        { Reserved for future use, must be zero }
  175.                 unused2: INTEGER;        { Reserved for future use, must be zero }
  176.                 unused: ARRAY[0..3] OF LONGINT;
  177.             END;
  178.  
  179.     {     Routines available in XTNDLibrary    }
  180.     FUNCTION XTNDInitTranslators (transVersion: INTEGER; xtndSystemName, clarisFolderName: Str255): OSErr;
  181.  
  182.     FUNCTION XTNDGetFile (paramPtr: SFParamPtr): BOOLEAN;
  183.  
  184.     FUNCTION XTNDPutFile (paramPtr: SFParamPtr): BOOLEAN;
  185.  
  186.     FUNCTION XTNDLoadTranslator (theTranslator: TransDescrPtr; VAR transResource: TransProcPtr): OSErr;
  187.  
  188.     FUNCTION XTNDReleaseTranslator (theTranslator: TransDescrPtr): OSErr;
  189.  
  190.     PROCEDURE XTNDCloseTranslators;
  191.  
  192.     FUNCTION XTNDRebuildTransList: OSErr;
  193.  
  194.     FUNCTION XTNDSelectTranslators (selectPtr: SelectParamPtr; transHandle: TransDescrHandle): OSErr;
  195.  
  196.     FUNCTION XTNDMatchFile (matchPtr: MatchTranslatorPtr): BOOLEAN;
  197.  
  198.     PROCEDURE XTNDCallTranslator (theParamBlock: UNIV Ptr; theProc: TransProcPtr);
  199.     INLINE
  200.         $205F,             {     MOVE.L    (SP)+,A0    ;    get translator address off stack }
  201.         $4E90,            {    JSR        (A0)        ;    Call it }
  202.         $584F;            {    ADDQ    #4,A7        ;    Adjust the stack (C calling conventions) }
  203.  
  204. IMPLEMENTATION
  205.     FUNCTION XTNDInitTranslators (transVersion: INTEGER; xtndSystemName, clarisFolderName: Str255): OSErr;
  206.     external;
  207.  
  208.     FUNCTION XTNDGetFile (paramPtr: SFParamPtr): BOOLEAN;
  209.     external;
  210.  
  211.     FUNCTION XTNDPutFile (paramPtr: SFParamPtr): BOOLEAN;
  212.     external;
  213.  
  214.     FUNCTION XTNDLoadTranslator (theTranslator: TransDescrPtr; VAR transResource: TransProcPtr): OSErr;
  215.     external;
  216.  
  217.     FUNCTION XTNDReleaseTranslator (theTranslator: TransDescrPtr): OSErr;
  218.     external;
  219.  
  220.     PROCEDURE XTNDCloseTranslators;
  221.     external;
  222.  
  223.     FUNCTION XTNDRebuildTransList: OSErr;
  224.     external;
  225.  
  226.     FUNCTION XTNDSelectTranslators (selectPtr: SelectParamPtr; transHandle: TransDescrHandle): OSErr;
  227.     external;
  228.  
  229.     FUNCTION XTNDMatchFile (matchPtr: MatchTranslatorPtr): BOOLEAN;
  230.     external;
  231. END.